<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Constructs the EvEmbed object</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.evembed.html">« EvEmbed</a></li>
      <li style="float: right;"><a href="evembed.createstopped.html">EvEmbed::createStopped »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.evembed.html">EvEmbed</a></li>
    <li>Constructs the EvEmbed object</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="evembed.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">EvEmbed::__construct</h1>
  <p class="verinfo">(PECL ev &gt;= 0.2.0)</p><p class="refpurpose"><span class="refname">EvEmbed::__construct</span> &mdash; <span class="dc-title">Constructs the EvEmbed object</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-evembed.construct-description">
  <h3 class="title">说明</h3>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="methodname"><strong>EvEmbed::__construct</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam">
    <span class="type">object</span>
     <code class="parameter">$other</code>
   </span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam">
    <span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span>
     <code class="parameter">$callback</code>
   <span class="initializer"> = ?</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam">
    <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span>
     <code class="parameter">$data</code>
   <span class="initializer"> = ?</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam">
    <span class="type">int</span>
     <code class="parameter">$priority</code>
   <span class="initializer"> = ?</span></span><br>)</div>

  <p class="para rdfs-comment">
   This is a rather advanced watcher type that lets to embed one event loop
   into another(currently only IO events are supported in the embedded loop,
   other types of watchers might be handled in a delayed or incorrect fashion
   and must not be used).
  </p>
  <p class="para">
   See
   <a href="http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#code_ev_embed_code_when_one_backend_" class="link external">&raquo;&nbsp;the
  libev documentation</a>
   for details.
  </p>
  <p class="para">
   This watcher is most useful on
   <em class="emphasis">BSD</em>
   systems without working
   <code class="literal">kqueue</code>
   to still be able to handle a large number of sockets. See example below.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-evembed.construct-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>

     <code class="parameter">other</code>
    </dt>

    <dd>

     <p class="para">
      Instance of
      <span class="classname"><a href="class.evloop.html" class="classname">EvLoop</a></span>
      . The loop to embed, this loop must be embeddable(see
      <span class="methodname"><a href="ev.embeddablebackends.html" class="methodname">Ev::embeddableBackends()</a></span>
      ).
     </p>
    </dd>

   
   
    <dt>

     <code class="parameter">callback</code>
    </dt>

    <dd>

     <p class="para">
      See
      <a href="ev.watcher-callbacks.html" class="link">Watcher callbacks</a>
      .
     </p>
    </dd>

   
   
    <dt>

     <code class="parameter">data</code>
    </dt>

    <dd>

     <p class="para">
      Custom data associated with the watcher.
     </p>
    </dd>

   
   
    <dt>

     <code class="parameter">priority</code>
    </dt>

    <dd>

     <p class="para">
      <a href="class.ev.html#ev.constants.watcher-pri" class="link">Watcher priority</a>
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 examples" id="refsect1-evembed.construct-examples">
  <h3 class="title">范例</h3>
 <div class="example" id="example-3258">
   <p><strong>示例 #1 Embedding loop created with kqueue backend into the default loop</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*<br />&nbsp;*&nbsp;Check&nbsp;if&nbsp;kqueue&nbsp;is&nbsp;available&nbsp;but&nbsp;not&nbsp;recommended&nbsp;and&nbsp;create&nbsp;a&nbsp;kqueue&nbsp;backend<br />&nbsp;*&nbsp;for&nbsp;use&nbsp;with&nbsp;sockets&nbsp;(which&nbsp;usually&nbsp;work&nbsp;with&nbsp;any&nbsp;kqueue&nbsp;implementation).<br />&nbsp;*&nbsp;Store&nbsp;the&nbsp;kqueue/socket-only&nbsp;event&nbsp;loop&nbsp;in&nbsp;loop_socket.&nbsp;(One&nbsp;might&nbsp;optionally<br />&nbsp;*&nbsp;use&nbsp;EVFLAG_NOENV,&nbsp;too)<br />&nbsp;*<br />&nbsp;*&nbsp;Example&nbsp;borrowed&nbsp;from<br />&nbsp;*&nbsp;http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#Examples_CONTENT-9<br />&nbsp;*/<br /></span><span style="color: #0000BB">$loop&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">EvLoop</span><span style="color: #007700">::</span><span style="color: #0000BB">defaultLoop</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$socket_loop&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$embed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">;<br /><br />if&nbsp;(</span><span style="color: #0000BB">Ev</span><span style="color: #007700">::</span><span style="color: #0000BB">supportedBackends</span><span style="color: #007700">()&nbsp;&amp;&nbsp;~</span><span style="color: #0000BB">Ev</span><span style="color: #007700">::</span><span style="color: #0000BB">recommendedBackends</span><span style="color: #007700">()&nbsp;&amp;&nbsp;</span><span style="color: #0000BB">Ev</span><span style="color: #007700">::</span><span style="color: #0000BB">BACKEND_KQUEUE</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;((</span><span style="color: #0000BB">$socket_loop&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">EvLoop</span><span style="color: #007700">(</span><span style="color: #0000BB">Ev</span><span style="color: #007700">::</span><span style="color: #0000BB">BACKEND_KQUEUE</span><span style="color: #007700">)))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$embed&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">EvEmbed</span><span style="color: #007700">(</span><span style="color: #0000BB">$loop</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />if&nbsp;(!</span><span style="color: #0000BB">$socket_loop</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$socket_loop&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$loop</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Now&nbsp;use&nbsp;$socket_loop&nbsp;for&nbsp;all&nbsp;sockets,&nbsp;and&nbsp;$loop&nbsp;for&nbsp;anything&nbsp;else<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>

 <div class="refsect1 seealso" id="refsect1-evembed.construct-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member">
    <span class="methodname"><a href="ev.embeddablebackends.html" class="methodname" rel="rdfs-seeAlso">Ev::embeddableBackends()</a> - Returns the set of backends that are embeddable in other event loops</span>
   </li>
  </ul>
 </div>

</div></div></div></body></html>